<!DOCTYPE html>
<html>
<head>
    <%include("/back/_include/meta.html",{"title":""}){}%>
    <%include("/back/_include/style.html"){}%>
    <link href="/assets/ui/h+/css/plugins/iCheck/custom.css" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-sm-12">
                            <form role="form" id="editForm">
                                <div class="form-group">
                                    <label>网站标题</label>
                                    <input type="text" id="title" name="title" value="${site.title!}" class="form-control" required="" minlength="2" maxlength="20">
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 2~20个字符以内</span>
                                </div>
                                <div class="form-group">
                                    <label class="control-label">logo</label>
                                    <div id="coverDiv">
                                        <img src="${site.logo!}">
                                        <input type="hidden" id="logo" value="${site.logo!}" name="logo" required>
                                        <div class="desc">
                                        </div>
                                    </div>
                                    <%include("/back/_include/img-cropper.html",{"cover":site.logo}){}%>
                                </div>
                                <div class="form-group">
                                    <label class="control-label">底部logo</label>
                                    <div id="coverDiv_2">
                                        <img src="${site.bottomLogo!}">
                                        <input type="hidden" id="bottomLogo" value="${site.bottomLogo!}" name="bottomLogo">
                                        <div class="desc">
                                        </div>
                                    </div>
                                    <%include("/back/_include/img-cropper_2.html",{"cover":site.bottomLogo}){}%>
                                </div>
                                <div class="form-group">
                                    <label>网址</label>
                                    <input type="text" id="url" name="url" value="${site.url!}" class="form-control" required="" minlength="2" maxlength="50">
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 2~50个字符以内</span>
                                </div>
                                <div class="form-group">
                                    <label>版权声明</label>
                                    <input type="text" id="copyright" name="copyright" value="${site.copyright!}" class="form-control" minlength="2" maxlength="50">
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 2~50个字符以内</span>
                                </div>
                                <div class="form-group">
                                    <label>固话</label>
                                    <input type="text" id="telephone" name="telephone" value="${site.telephone!}" class="form-control" minlength="2" maxlength="20">
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 2~20个字符以内</span>
                                </div>
                                <div class="form-group">
                                    <label>联系邮箱</label>
                                    <input type="text" id="email" name="email" value="${site.email!}" class="form-control" minlength="2" maxlength="20">
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 2~20个字符以内</span>
                                </div>
                                <div class="form-group">
                                    <label>手机号码</label>
                                    <input type="text" id="mobile" name="mobile" value="${site.mobile!}" class="form-control" minlength="11" maxlength="11">
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 11位数字</span>
                                </div>
                                <div class="form-group">
                                    <label>qq</label>
                                    <input type="text" id="qq" name="qq" value="${site.qq!}" class="form-control" minlength="2" maxlength="20">
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 2~20个字符以内</span>
                                </div>
                                <div class="form-group">
                                    <label>二维码</label>
                                    <img src="${site.qrCode!}" id="qrCode_img" style="display: block">
                                    <input type="file" id="qrCode" name="qrCode" value="${site.qrCode!}" class="hide">
                                </div>
                                <div class="form-group">
                                    <label>地址</label>
                                    <textarea id="address" name="address" class="form-control" minlength="2" maxlength="100">${site.address!}</textarea>
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 2~100个字符以内</span>
                                </div>
                                <div class="form-group">
                                    <label>seo关键词</label>
                                    <textarea id="keyword" name="keyword" class="form-control" minlength="2" maxlength="80">${site.keyword!}</textarea>
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 2~80个字符以内</span>
                                </div>
                                <div class="form-group">
                                    <label>seo描述</label>
                                    <textarea id="description" name="description" class="form-control" minlength="2" maxlength="150">${site.description!}</textarea>
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 2~150个字符以内</span>
                                </div>
                                <div class="form-group">
                                    <label>统计代码</label>
                                    <textarea id="siteTrackCode" name="siteTrackCode" class="form-control" minlength="2" maxlength="100">${site.siteTrackCode!}</textarea>
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 2~100个字符以内</span>
                                </div>
                                <div class="form-group">
                                    <label>ip访问限制</label>
                                    <input type="checkbox" id="open_ip" <%if(site.open_ip){%>checked<%}%> name="open_ip" class="i-checks form-control">
                                </div>
                                <div>
                                    <button class="btn btn-lg btn-primary pull-left" id="save">
                                        <strong>更新</strong>
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<form enctype="multipart/form-data" method="post" class="hide" id="form">
</form>
<%include("/back/_include/script.html"){}%>
<%include("/back/_include/img-cropper.js.html",{"uploadUrl":"/b/upload/img?system=backend&module=site&noResize=true"}){}%>
<%include("/back/_include/img-cropper_2.js.html",{"uploadUrl":"/b/upload/img?system=backend&module=site&noResize=true"}){}%>
<script src="/assets/ui/h+/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/assets/ui/h+/js/plugins/validate/messages_zh.min.js"></script>
<script src="/assets/ui/h+/js/plugins/iCheck/icheck.min.js"></script>
<script>
    var qr_code;
    $.validator.setDefaults({
        submitHandler: function() {
            var title = $$('#title')
            var logo = $$('#logo')
            var bottomLogo = $$('#bottomLogo')
            var url = $$('#url')
            var copyright = $$('#copyright')
            var telephone = $$('#telephone')
            var mobile = $$('#mobile')
            var email = $$('#email')
            var qq = $$('#qq')
            var address = $$('#address')
            var keyword = $$('#keyword')
            var description = $$('#description')
            var siteTrackCode = $$('#siteTrackCode')
            var formData = new FormData($( "#form" )[0])
            formData.append("site.id", "${site.id!}");
            formData.append("site.title", title);
            formData.append("site.logo", logo);
            formData.append("site.bottom_logo", bottomLogo);
            formData.append("site.url", url);
            formData.append("site.copyright", copyright);
            formData.append("site.telephone", telephone);
            formData.append("site.mobile", mobile);
            formData.append("site.email", email);
            formData.append("site.qq", qq);
            formData.append("qrCodeFile", qr_code);
            formData.append("site.address", address);
            formData.append("site.keyword", keyword);
            formData.append("site.description", description);
            formData.append("site.site_track_code", siteTrackCode);
            formData.append("site.open_ip", $("#open_ip").prop("checked"));
            ajaxFormData("/b/site/update",formData,function (res) {
                if(!res.success){
                    error(res.msg)
                    return;
                }
                success("更新成功",false,function () {
                    window.location.reload();
                })
            },function () {
                systemErr();
            })
        }
    });
    $(function () {
        $(".i-checks").iCheck({checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green",})
        $('#qrCode_img').click(function () {
            $('#qrCode').trigger("click")
        })
        $('#qrCode').change(function(e){
            var file = this.files[0];
            qr_code = file;
            var size = parseInt(file.size/1024);
            if(size>=500){
                error("图片大小不能超过500kb,当前文件大小:<span style='color: #f00'>"+size+"</span>kb");
                return;
            }
            var url=getObjectURL(file);
            $('#qrCode_img').attr("src",url).removeClass("hide");

        })
        $("#editForm").validate({
            messages: {
                title: {required:"请输入网站标题", minlength:"标题必须2个字符以上",maxlength:"标题必须20个字符以下"},
                logo: {required:"请上传网站logo"},
                url: {required:"请输入网址", minlength:"网址必须2个字符以上",maxlength:"网址必须50个字符以下"},
            }
        })
    });
</script>
</body>
</html>